﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Maticsoft.Model.CarrefourCover;
using Common;
using Shanda.Utility;
using WebSite.Core;

namespace WebSite.Server
{
    /// <summary>
    /// HMessage 的摘要说明
    /// </summary>
    public class HMessage : ServiceBase
    {

        protected override string DoProcess(HttpContext context)
        {
            string ret = string.Empty;
            string CallMethod = WebUtils.GetPostValue(context.Request, "method", string.Empty);
            switch (CallMethod)
            {
                case "new":
                    ret = AddNew(context);
                    break;
                case "update":
                    ret = Update(context);
                    break;
                case "del":
                    ret = Del(context);
                    break;
                case "get":
                    ret = Get(context);
                    break;
                case "list":
                    ret = List(context);
                    break;
                default:
                    break;
            }
            return ret;
        }

        /// <summary>
        /// new
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string AddNew(HttpContext context)
        {
            RetInfo response = RetInfoHelper.WebServiceReturn(delegate()
            {
                var bll = new Maticsoft.BLL.CarrefourCover.Message();
                int dbResult = bll.Add(new Message() { });
                if (dbResult <= 0)
                {
                    throw new RuntimeException((int)ErrorVoteCode.Create_Error, "创建失败");
                }
                return true;
            });
            return response.SerializeToString(Common.Serialization.SerializationType.Json);
        }
        /// <summary>
        /// update
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Update(HttpContext context)
        {
            RetInfo response = RetInfoHelper.WebServiceReturn(delegate()
            {
                var bll = new Maticsoft.BLL.CarrefourCover.Message();
                bool dbResult = bll.Update(new Message() { });
                if (!dbResult)
                {
                    throw new RuntimeException((int)ErrorVoteCode.Update_Error, "修改失败");
                }
                return true;
            });
            return response.SerializeToString(Common.Serialization.SerializationType.Json);
        }
        /// <summary>
        /// del
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private string Del(HttpContext context)
        {
            RetInfo response = RetInfoHelper.WebServiceReturn(delegate()
            {
                var bll = new Maticsoft.BLL.CarrefourCover.Message();
                int sId = WebUtils.GetPostValue(context.Request, "Id", 0);
                bool dbResult = bll.Delete(sId);
                if (!dbResult)
                {
                    throw new RuntimeException((int)ErrorVoteCode.Del_Error, "删除失败");
                }
                return true;
            });
            return response.SerializeToString(Common.Serialization.SerializationType.Json);
        }

        private string Get(HttpContext context)
        {
            return string.Empty;
        }


        private string List(HttpContext context)
        {
            return string.Empty;
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}